package com.zzyl.nursing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.HealthAssessment;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.dto.PageNursingProjectDto;
import com.zzyl.nursing.mapper.HealthAssessmentMapper;
import com.zzyl.nursing.mapper.MemberProjectMapper;
import com.zzyl.nursing.service.IMemberProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberProjectServiceImpl extends ServiceImpl<MemberProjectMapper, NursingProject> implements IMemberProjectService {
    @Autowired
    private MemberProjectMapper memberProjectMapper;
    @Override
    public TableDataInfo<NursingProject> getPage(PageNursingProjectDto pageNursingProjectDto) {
        // 1. 计算分页偏移量（(pageNum-1)*pageSize）
        int offset = (pageNursingProjectDto.getPageNum() - 1) * pageNursingProjectDto.getPageSize();

        // 2. 查询当前页商品列表
        List<NursingProject> productList = memberProjectMapper.selectProductPage(
                pageNursingProjectDto.getName(),
                pageNursingProjectDto.getStatus(),
                offset,
                pageNursingProjectDto.getPageSize()
        );

        // 3. 查询符合条件的商品总数
        long total = memberProjectMapper.countProduct(
                pageNursingProjectDto.getName(),
                pageNursingProjectDto.getStatus()
        );

        // 4. 封装分页结果
        TableDataInfo<NursingProject> tableData = new TableDataInfo<>(productList,  total);
        tableData.setCode(200); // 成功状态码
        tableData.setMsg("查询成功"); // 提示信息

        return tableData;

    }

    @Override
    public NursingProject findById(Integer id) {
        return getById(id);
    }
}
